package cn.com.dhc.danlu.business.shopcar.holder;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.com.dhc.danlu.R;
import cn.com.dhc.danlu.activity.delivery.order.viewholder.BaseViewHolder;
import cn.com.dhc.danlu.business.shopcar.bean.PromotionBean;
import cn.com.dhc.danlu.widget.dialog.PromotionDetailDialog;

/**
 * author: 李一方(<a href="mailto:liyifang@danlu.com">liyifang@danlu.com</a>)<br/>
 * version: 1.0.0<br/>
 * since: 2017-02-27 17:05
 *
 * <p>
 * 促销汇总区的 ViewHolder
 * </p>
 */
public class PromotionViewHolder extends BaseViewHolder<PromotionBean> {
    private TextView tvGift;
    private TextView tvReduce;
    private LinearLayout llRoot;
    private LinearLayout llReduce;

    public PromotionViewHolder(View itemView) {
        super(itemView);

        initViews();
        setViews();
    }

    private void initViews() {
        tvGift = (TextView) itemView.findViewById(R.id.tv_gift);
        tvReduce = (TextView) itemView.findViewById(R.id.tv_reduce);
        llRoot = (LinearLayout) itemView.findViewById(R.id.ll_root);
        llReduce = (LinearLayout) itemView.findViewById(R.id.ll_reduce);
    }

    private void setViews() {
        itemView.findViewById(R.id.ll_promotion)
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // TODO: 2017/3/7 弹窗显示促销细节 @lyf #ok
                        PromotionDetailDialog detailDialog = new PromotionDetailDialog(getContext());
                        detailDialog.refreshContent(data.getPromotion());
                        detailDialog.show();
                    }
                });
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void bindViewData(PromotionBean data) {
        if (TextUtils.isEmpty(data.getMsgReduce()) && TextUtils.isEmpty(data.getMsgGift())) {
            llRoot.setVisibility(View.GONE);
            return;
        }

        if (data.isValid()) {
            llRoot.setVisibility(View.VISIBLE);

            if (TextUtils.isEmpty(data.getMsgReduce())) {
                llReduce.setVisibility(View.GONE);
            } else {
                llReduce.setVisibility(View.VISIBLE);
                tvReduce.setText("¥" + data.getMsgReduce());
            }

            if (TextUtils.isEmpty(data.getMsgGift())) {
                tvGift.setVisibility(View.GONE);
            } else {
                tvGift.setVisibility(View.VISIBLE);
                tvGift.setText("促销赠送：".concat(data.getMsgGift()));
            }
        } else {
            llRoot.setVisibility(View.GONE);
        }
    }
}
